import tool from '../tool'
import util from '_util/index'
import logic from '_logic'
const store = util.store
import _ from 'lodash'

export default{
    get_submit_clb(_this){
        if (_this.isAdd || _this.otherEdit)
            return this.do_sync;
    },
    do_sync(_this, rs = null){
        if (!rs) {
            return;
        }

        let state = logic.edit.get_vo_state(_this);
        let vo = _this.$store.state.global[state];
        util.getHardCode(_this, 'sync_sys_en', (sync_sys) => {
            util.getHardCode(_this, 'env_en_sync', (env) => {

                let _sys = sync_sys.find(item => {
                    return item.id == vo['sync_sys'];
                }).title;
                let _env = env.find(item => {
                    return item.id == vo['sync_to'];
                }).title;
                // tool.cl('rs:', rs);
                // tool.cl('_sys:', _sys);
                // tool.cl('_env:', _env);
                let url = `http://192.168.40.88:3000/shell/${_env}/${_sys}`;
                // tool.cl('url:', url);
                util.http.SR(_this, url, vo, '操作成功', (result) => {
                    let url = tool.getApi(_this, 'Op', 'set_sync_status');
                    // tool.cl('url2:', url);
                    // tool.cl('result:', result);
                    let info = {
                        status: 2,
                        id: rs.id,
                        result
                    };
                    util.http.SR(_this, url, info, false, (rs) => {
                        tool.cl('rs2:', rs);
                    });
                });

            })
        })

    }
};
